//
//  YWGetNewsTool3.m
//  YueshengToutiao
//
//  Created by jun peng on 2022/1/26.
//  Copyright © 2022 YW. All rights reserved.
//

#import "YWGetNewsTool3.h"

@implementation YWGetNewsTool3
+ (void)getNewsListStatusesWithParameters:(YWGetNewsListParam *)param success:(void(^)(YWGetNewsListStatus *status))success failure:(void(^)(NSError *error))failure{
    
    
    NSString *url = [NSString stringWithFormat:@"%@/api/UserInfo/GetNewsByTypePages",domainURL];
    
    
    [YWHttpTool Post:url parameters:param.keyValues success:^(id responseObject) {
        
        //        YWLog(@"%@",responseObject);
                
                NSMutableDictionary *dictionary = (NSMutableDictionary *)responseObject;

                id ResultObj = dictionary[@"ResultObj"];

                if ([ResultObj isKindOfClass:[NSNull class]]) {

                    [dictionary setObject:[NSDictionary dictionary] forKey:@"ResultObj"];
                }
                else{
                    
                    id PageInfo = ResultObj[@"PageInfo"];
                    if ([PageInfo isKindOfClass:[NSNull class]]) {
                         [ResultObj setObject:[NSArray array] forKey:@"PageInfo"];
                    }
                    else{
                        
                        NSArray *PageInfoArray = (NSArray *)PageInfo;
                        for (NSMutableDictionary *dataDic in PageInfoArray) {
                            
                            id ArrImg = dataDic[@"ArrImg"];
                            if ([ArrImg isKindOfClass:[NSNull class]]) {
                                 [dataDic setObject:[NSArray array] forKey:@"ArrImg"];
                            }
                            
                        }
                        
                    }
                   
                }
        
 
 //试用这个方法、但是最多只能将原来是string类型返回null有效、但是对于原来是NSDictionary或者array类型的返回null但是转为了@“”依然会奔溃的 (所以我选择了与上面代码一起配合)
 NSDictionary *dic = [NSDictionary nullDic:dictionary];
        
        
        
      
        YWGetNewsListStatus *status = [YWGetNewsListStatus objectWithKeyValues:dic] ;
        
        
        // 传递了block
        if (success) {
            success(status);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
        
    }];
    
    
}

@end
